package chapter05.shiyan3;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;

import java.util.Scanner;

public class project1 {
    public static void main(String[] args) {
        int n = 0;
        int l = 0;
        int[] a = null;
        try {
            Scanner scanner = new Scanner(new File("./src/chapter05/shiyan3/prog10.in"));
            n = scanner.nextInt();
            l = scanner.nextInt();
            a = new int[n];
            int i = 0;
            while (scanner.hasNext()) {
                a[i++] = scanner.nextInt();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        assert a!=null:"a is null";//断言，是否将文件读入
        int sum = 0;
        int max = 0;
        Arrays.sort(a);
        for (int i = 0; i < n; i++) {
            sum += a[i];
            if (sum > l) {
                max = i;
                break;
            }
        }
        System.out.println(max);
    }
//

//    public static int input(){
//        FileInputStream fileInputStream = null;
//        try {
//            fileInputStream = new FileInputStream("C:\\Users\\levovo\\Desktop\\实验3 贪心算法\\prog10.in");
//        } catch (FileNotFoundException e) {
//
//            e.printStackTrace();
//        }
//        Scanner scanner =new Scanner(fileInputStream);
//        int n=scanner.nextInt();
//        int l=scanner.nextInt();
//        int[] a=new int[l];
//        for (int i = 0; i < a.length; i++) {
//            a[i]= scanner.nextInt();
//        }
//        int sum=0;
//        int max=0;
//
//        Arrays.sort(a);
//        for (int i = 0; i < n; i++) {
//            sum+=a[i];
//            if(sum>l){
//                max=i;
//                  break;
//            }
//        }
//        return max;
//
//    }
}
